//虚拟定位
function Change_Location(){
    for (let i = 0; i < 5; i++) {
        home();
        sleep(1000);
        Next_Page();
        sleep(1000);
        if (Click_loc()) {
            home();
            sleep(1000);
            return true;
        }else {
            for (let j = 0; j < 5; j++) {
                back();
                sleep(300);
            }
        }
    }
    return false;
}

function Next_Page(){
    var next_page = id("com.huang.autorunmarket:id/goRightView");
    var result = has(next_page);
    if (result) {
        click(next_page);
        logd("进入下一页");
    }
}

function Click_loc(){
    var location1 = text("虚拟定位");
    if (has(location1)) {
        click(location1);
        logd("打开虚拟定位");
        sleep(1000);

        while (1){
            var wait1 = text("正在初始化...");
            if (has(wait1)) {
                logd("正在初始化...请稍等");
                sleep(1500);
            }else {
                break;
            }
        }
        sleep(1000);
        var location2 = text("定位到ip所在地");
        if (has(location2)) {
            click(location2);
            logd("定位到ip所在地");
            sleep(2000);

            while (1){
                var wait2 = text("请稍后");
                if (has(wait2)) {
                    logd("正在定位中...请稍等");
                    sleep(2000);
                }else {
                    sleep(1000);
                    var go = text("穿越");
                    if (has(go)) {
                        click(go);
                        logd("点击穿越");
                        sleep(1500);
                        return true;
                    }else {
                        toast("定位失败");
                        return false;
                    }
                }
            }
        }else {
            toast("定位到ip所在地失败");
            return false;
        }
    }else {
        toast("没有找到虚拟定位APP");
        return false;
    }
}

// Change_Location();